package com.taxi.controller;

import com.taxi.dto.PassengerUser;
import com.taxi.request.VerificationCodeDTO;
import com.taxi.result.Result;
import com.taxi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: aniu
 * @Date: 2023/9/20
 * @ClassName: UserController
 * @Description: Write class functionality and purpose here.
 * @Version: 1.0
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/user")
    public Result loginOrReg(@RequestBody VerificationCodeDTO verificationCodeDTO){
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        return userService.loginOrResult(passengerPhone);
    }

    /**
     * 根据id查询乘客信息
     */
    @GetMapping("/get-passenger-info/{passengerId}")
    public Result<PassengerUser> getPassengerInfo(@PathVariable("passengerId") Long passengerId){
        return userService.getPassengerInfoById(passengerId);
    }

    @GetMapping("/user/{phone}")
    public Result getUserByPhone(@PathVariable("phone")String passengerPhone){
        return userService.getUserByPhone(passengerPhone);
    }

    @GetMapping("/user/list")
    public Result getUserList(@RequestParam int page, @RequestParam int limit,@RequestParam(required = false) String passengerPhone){
        return userService.getUserList(page,limit,passengerPhone);
    }
}
